// pages/driveway/driveway.js
const host=getApp().globalData.host;
Page({

      /**
       * 页面的初始数据
       */
      data: {
            list:[],
            userId:''
      },
      // 我有意向
      hanleIntention(e){
            wx.makePhoneCall({
                  phoneNumber:e.currentTarget.dataset.contact,
                  fail:()=>{
                        wx.showToast({
                              title: '暂不提供服务',
                              icon:'error'
                        })
                  }
            })
      },
      init(){
            wx.showLoading({
                  title: '加载数据',
            })
            this.setData({
                  userId:wx.getStorageSync('userId')
            })

            let communityId=wx.getStorageSync('userInfo').housingId;
            wx.request({
                  url: host+'client/driveway/list?communityId='+communityId,
                  success:res=>{
                        console.log(res);
                        this.setData({
                              list:res.data.data.list
                        })
                  },
                  fail:()=>{
                        wx.showToast({
                          title: '服务器繁忙',
                          icon:'error'
                        })
                  },
                  complete:()=>{
                        wx.hideLoading()
                  }
            })
      },

      /**
       * 生命周期函数--监听页面显示
       */
      onShow: function () {
            let userInfo=wx.getStorageSync("userInfo");
            if(userInfo.nickName==null || userInfo.nickName==""){
                  wx.showModal({
                        title: '未登录',
                        content: '是否进行登录？',
                        success: (res)=> {
                              if (res.confirm) {
                                    wx.navigateTo({
                                          url:'/pages/login/login'
                                    })
                              } else if (res.cancel) {
                                    // 点击取消后返回主页面
                                    wx.switchTab({
                                          url: '/pages/index/index'
                                    })
                                    wx.showToast({
                                          title: '需要登录',
                                          icon: 'error'
                                    })
                              }
                        }
                  })
            }else if(userInfo.addr == undefined || userInfo.addr == "null" || userInfo.addr == "" || userInfo.addr == null){
                  wx.showModal({
                        title: '未完善信息',
                        content: '需要补全房屋信息',
                        success: (res)=> {
                              if (res.confirm) {
                                    wx.navigateTo({
                                          url:'/pages/userInfo/userInfo'
                                    })
                              } else if (res.cancel) {
                                    // 点击取消后返回主页面
                                    wx.switchTab({
                                          url: '/pages/index/index'
                                    })
                                    wx.showToast({
                                          title: '需要完善信息',
                                          icon: 'error'
                                    })
                              }
                        }
                  })
            }else{
                  this.init();
            }
      },
})